#include <iostream>
using namespace std;
int main()
{
	unsigned long long n;
	while(cin>>n){
		if(n==0) break;
		unsigned long long sum=n;
		int a[200];
		while(sum>=10){
			unsigned long long temp=sum;
			sum=0;
			while(temp>0){
				sum=sum+temp%10;
				temp=temp/10;
			}
		}
		cout<<sum<<endl;
	}
}
